package com.dt76.smallloanbackenduser.controller.xm;

import com.dt76.smallloanbackenduser.pojo.xm.BeforeOrder;
import com.dt76.smallloanbackenduser.pojo.xm.FcCheckState;
import com.dt76.smallloanbackenduser.remote.xm.BeforeOrderRemote;
import com.dt76.smallloanbackenduser.remote.xm.FcCheckStateRemote;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/xm")
public class FcCheckStateController {

    @Resource
    private FcCheckStateRemote fcCheckStateRemote;
    @Resource
    private BeforeOrderRemote beforeOrderRemote;

    @RequestMapping("/checkStateAdd")
    @ResponseBody
    public Boolean checkStateAdd(FcCheckState checkState, String csboID){
        Boolean result = false;

        checkState.setmType(1);
        //给审核记录加上订单号
        checkState.setBoId(Long.parseLong(csboID));

        //根据订单ID查询订单
        BeforeOrder beforeOrder = beforeOrderRemote.qryByID(Integer.parseInt(csboID));
        System.out.println(beforeOrder);

        //更新订单状态
        beforeOrder.setBoType(checkState.getmResult());
        beforeOrderRemote.modifyBeforeOrderType(beforeOrder);

        //添加审核记录
        int i = fcCheckStateRemote.addCheckState(checkState);
        if(i>0){
            result = true;
        }
        return result;
    }

    @RequestMapping("/checkStateAdd2")
    @ResponseBody
    public Boolean checkStateAdd2(FcCheckState checkState, String csboID){
        Boolean result = false;

        checkState.setmType(2);
        //给审核记录加上订单号
        checkState.setBoId(Long.parseLong(csboID));
        //根据订单ID查询订单
        BeforeOrder beforeOrder = beforeOrderRemote.qryByID(Integer.parseInt(csboID));
        System.out.println(beforeOrder);
        //更新订单状态
        beforeOrder.setBoType(checkState.getmResult());
        beforeOrderRemote.modifyBeforeOrderType(beforeOrder);

        //添加审核记录
        int i = fcCheckStateRemote.addCheckState(checkState);
        if(i>0){
            result = true;
        }
        return result;
    }

    @RequestMapping("/checkStateQuery")
    @ResponseBody
    public Map<String,Object> qryCheckStateById(String boId){
        Map<String,Object> map = new HashMap<>();
        List<FcCheckState> checkStates = fcCheckStateRemote.qryAllCheckStateByID(Integer.parseInt(boId));
        for (FcCheckState checkState:checkStates) {
            System.out.println(checkState.toString());
        }
        map.put("checkStates",checkStates);
        return map;
    }
}
